/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cse308.entities;

import cse308.GeneralEntity;
import cse308.helper_classes.GeneralTest;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Aaron
 */
@Entity
@Table(catalog = "nchorn", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Survey.findAll", query = "SELECT s FROM Survey s"),
    @NamedQuery(name = "Survey.findByGroupBelong", query = "SELECT s FROM Survey s WHERE s.groupBelong = :groupBelong"),
    @NamedQuery(name = "Survey.findByInitiator", query = "SELECT s FROM Survey s WHERE s.initiator = :initiator"),
    @NamedQuery(name = "Survey.findBySemester", query = "SELECT s FROM Survey s WHERE s.semester = :semester"),
    @NamedQuery(name = "Survey.findByIdentifier", query = "SELECT s FROM Survey s WHERE s.identifier = :identifier")})
public class Survey implements Serializable, GeneralEntity {

    private static final long serialVersionUID = 1L;
    @Size(max = 20)
    @Column(length = 20)
    private String groupBelong;
    @Size(max = 20)
    @Column(length = 20)
    private String initiator;
    @Size(max = 20)
    @Column(length = 20)
    private String semester;
    @Lob
    private byte[] results;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(nullable = false)
    private Integer identifier;
    @ManyToMany(mappedBy = "surveyCollection")
    private Collection<Degreeprogram> degreeprogramCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "survey1")
    private Collection<Surveyattainmentlevels> surveyattainmentlevelsCollection;
    @OneToMany(mappedBy = "surveyidentifier")
    private Collection<Peoattainment> peoattainmentCollection;
    @Size(max = 4)
    private Integer isAlumni;

    public Survey() {
        this.degreeprogramCollection = new ArrayList();
        this.surveyattainmentlevelsCollection = new ArrayList();
        this.peoattainmentCollection = new ArrayList();
    }

    public Survey(Integer identifier) {
        this.identifier = identifier;
        this.degreeprogramCollection = new ArrayList();
        this.surveyattainmentlevelsCollection = new ArrayList();
        this.peoattainmentCollection = new ArrayList();
    }

    public String getGroupBelong() {
        return groupBelong;
    }

    public void setGroupBelong(String groupBelong) {
        this.groupBelong = groupBelong;
    }

    public String getInitiator() {
        return initiator;
    }

    public void setInitiator(String initiator) {
        this.initiator = initiator;
    }

    public String getSemester() {
        return semester;
    }

    public void setSemester(String semester) {
        this.semester = semester;
    }

    public byte[] getResults() {
        return results;
    }

    public void setResults(byte[] results) {
        this.results = results;
    }

    public Integer getIdentifier() {
        return identifier;
    }

    public void setIdentifier(Integer identifier) {
        this.identifier = identifier;
    }

    @XmlTransient
    public Collection<Degreeprogram> getDegreeprogramCollection() {
        return degreeprogramCollection;
    }

    public void setDegreeprogramCollection(Collection<Degreeprogram> degreeprogramCollection) {
        this.degreeprogramCollection = degreeprogramCollection;
    }

    @XmlTransient
    public Collection<Surveyattainmentlevels> getSurveyattainmentlevelsCollection() {
        return surveyattainmentlevelsCollection;
    }

    public void setSurveyattainmentlevelsCollection(Collection<Surveyattainmentlevels> surveyattainmentlevelsCollection) {
        this.surveyattainmentlevelsCollection = surveyattainmentlevelsCollection;
    }

    @XmlTransient
    public Collection<Peoattainment> getPeoattainmentCollection() {
        return peoattainmentCollection;
    }

    public void setPeoattainmentCollection(Collection<Peoattainment> peoattainmentCollection) {
        this.peoattainmentCollection = peoattainmentCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (identifier != null ? identifier.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Survey)) {
            return false;
        }
        Survey other = (Survey) object;
        if ((this.identifier == null && other.identifier != null) || (this.identifier != null && !this.identifier.equals(other.identifier))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "cse308.entities.Survey[ identifier=" + identifier + " ]";
    }

    @Override
    public List<GeneralEntity> getAssociatedClass(String associated) {
        if (associated.equals(Surveyattainmentlevels.class.getSimpleName())) {
            return (List) this.surveyattainmentlevelsCollection;
        } else if (associated.equals((Degreeprogram.class.getSimpleName()))) {
            return (List) this.degreeprogramCollection;
        }
        return null;
    }

    @Override
    public void setWithClass(GeneralTest gt) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void testAddClass(GeneralEntity ge) {

        if (ge instanceof Surveyattainmentlevels) {
            this.surveyattainmentlevelsCollection.add((Surveyattainmentlevels) ge);
        } else if (ge instanceof Degreeprogram) {
            this.degreeprogramCollection.add((Degreeprogram) ge);
        }
    }

    @Override
    public void removeClass(GeneralEntity ge) {
        if (ge instanceof Surveyattainmentlevels) {
            this.surveyattainmentlevelsCollection.remove((Surveyattainmentlevels) ge);
        } else if (ge instanceof Degreeprogram) {
            this.degreeprogramCollection.remove((Degreeprogram) ge);
        }
    }

    @Override
    public GeneralEntity findCorrespondingEntity() {
        return this;
    }

    @Override
    public String getIdentifier2() {
        return String.valueOf(this.identifier);
    }

    @Override
    public boolean equalsEntity(GeneralEntity entity) {
        return this.equals(entity);
    }

    @Override
    public List<List<GeneralEntity>> getAssociatedClasses() {
        List<List<GeneralEntity>> associatedClasses = new ArrayList<List<GeneralEntity>>();
        associatedClasses.add((List) this.surveyattainmentlevelsCollection);
        associatedClasses.add((List) this.degreeprogramCollection);
        return associatedClasses;
    }

    @Override
    public Object getPK() {
        return this.identifier;
    }

    public Integer getIsAlumni() {
        return isAlumni;
    }

    public void setIsAlumni(Integer isAlumni) {
        this.isAlumni = isAlumni;
    }
}
